package cn.valo.system.Listener;

import cn.valo.system.service.IPermissionScanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
@Slf4j
public class PermissionScanListener  implements ServletContextListener {
    @Autowired
    private IPermissionScanService permissionScanService;

    /**
     * Spring容器装载完成，执行此方法
     * @param sce
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        new Thread(new Runnable() {
            // 执行异步线程的业务
            @Override
            public void run() {
                log.info("开启权限扫描");
                permissionScanService.scan();
                log.info("结束权限扫描");
            }
        }).start();//启动异步线程
    }
}
